package com.itgone.manager.test;

import org.apache.logging.log4j.util.Strings;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Objects;

/**
 * @Author: earlman
 * @Description:
 * @Date:Create：in 2021-08-27 10:53
 */
public class FuWangMain {
    public static void main(String[] args) throws IOException {
        Workbook wb = new XSSFWorkbook(new FileInputStream(
//                new File("C:\\Users\\Earlman\\Desktop\\DCS远程诊断点数据配置\\新建 Microsoft Excel 工作表.xlsx")));
                new File("D:\\北三出差\\远程诊断系统安装\\设备数据整理文件\\现场整理\\0公网机组.xlsx")));
        Sheet sheetAt = wb.getSheetAt(0);
        int lastRowNum = sheetAt.getLastRowNum();

        for (int rowNum = 0; rowNum < lastRowNum; rowNum++) {
            Row row = sheetAt.getRow(rowNum);
            short lastCellNum = row.getLastCellNum();
            System.out.print(rowNum + "  : ");
            for (int colNum = 0; colNum < lastCellNum; colNum++) {
                Cell cell = row.getCell(colNum);
                System.out.print(getValue(cell));
                System.out.print("\t");
            }
            System.out.println();
        }
    }

    private static String getValue(Cell cell) {
        if (Objects.isNull(cell)) {
            return Strings.EMPTY;
        }

        if (cell.getCellType() == CellType.BOOLEAN) {
            return String.valueOf(cell.getBooleanCellValue());
        } else if (cell.getCellType() == CellType.NUMERIC) {
            return String.valueOf(cell.getNumericCellValue());
        }
        return String.valueOf(cell.getStringCellValue());
    }
}
